package edu.hawaii.webspider;

import static org.junit.Assert.*;

import org.junit.Test;
/**
 * TotalLinksTest class tests the TotalLinks class.
 * @author kenglish
 *
 */
public class TestMostPopular {
  MostPopular mostPopular ;
  private static final String invalidUrl = "http://www.123sdf`1234asdfa1234sdaf''dsf.edu";
  private static final String noLinksUrl = "http://www.kenglish77.com/613/tests/nolinks.html";
  /**
   * Test the total links.
   *
   */
  @Test
  public void testMostPopular() {
    String url = "http://www.hawaii.edu";
    mostPopular = new MostPopular(url);    
    assertEquals("constructor should set start url ",mostPopular.getStartUrl(),url);
  }
  
  /**
   * Test the getLinks() method.
   */
  @Test  
  public void testGetLinks() {
    String url = "http://www.yahoo.com";
    mostPopular = new MostPopular(url); 
    assertTrue("Should have more than one link for" + url ,
                mostPopular.getMostPopularLink(10).startsWith("http:") );
  }  
  /**
   * Test getLinks() method, should fail.
   *
   */  
  @Test
  public void testGetLinksFail() {
    mostPopular = new MostPopular(invalidUrl); 
    assertEquals("Should have no links for" + invalidUrl ,mostPopular.getMostPopularLink(2),null);
  }
  /**
   * Test getLinks() method with a page that has no links.
   *
   */    
  @Test
  public void testGetLinksNoLinks() {
    mostPopular = new MostPopular(noLinksUrl); 
    assertEquals("Should have no links for" + noLinksUrl ,mostPopular.getMostPopularLink(2),null);
  }
  /**
   * Test getLinks(), also calls main to ensure we get full coverage. 
   *  
   */
  @Test
  public void testGetLinksNoLinksandMain() {
    mostPopular = new MostPopular(noLinksUrl); 
    assertEquals("Should have no links for" + noLinksUrl ,mostPopular.getMostPopularLink(2),null);
    TotalLinks.main(new String[1]);
  }
  
  

}
